package cn.edu.ctbu.studentmanage.service.impl;

import cn.edu.ctbu.studentmanage.domain.Dept;
import cn.edu.ctbu.studentmanage.repository.DeptRepository;
import cn.edu.ctbu.studentmanage.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DeptImplService implements DeptService {
    @Autowired
    private DeptRepository deptRepository;

    /**
     * 查询所有院系信息
     * @return
     */
    public List<Dept> findAll(){

        return deptRepository.findAll();
    }

    /**
     * 分页
     * @param pageable
     * @return
     */
    public Page<Dept> findAll(Pageable pageable) {

        return deptRepository.findAll(pageable);
    }
    /**
     * 分页加动态查询
     * @param deptExample
     * @param pageable
     * @return
     */
    public Page<Dept> findAll(Example<Dept> deptExample, Pageable pageable){
        return deptRepository.findAll(deptExample,pageable);
    }
    /**
     * 根据id获取院系信息
     * @param did
     * @return
     */
    public Dept getByDid(Integer did){

        return deptRepository.findById(did).orElse(null);
    }
    /**
     * 更新院系信息
     * @param dept
     */
    public void update(Dept dept){
        deptRepository.save(dept);
    }
    /**
     * 根据id删除某一院系
     * @param did
     */
    public void delete(Integer did){
        deptRepository.deleteById(did);
    }
    /**
     * 插入新的院系
     * @param dept
     */
    public void Insert(Dept dept){
        deptRepository.save(dept);
    }

}
